package com.yr.ryjk.district;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.district.entity.District;
import com.yr.ryjk.district.service.IDistrictService;
import com.yr.ryjk.util.JSONUtil;

/**
 * 地区,全国省市区
 * @author Rick
 *
 */
@Controller
@RequestMapping(value="/district",method=RequestMethod.GET)
@ResponseBody
public class DistrictController {
	@Autowired
	private IDistrictService districtService;
	/**
	 * 获取所有省份
	 * @return
	 */
	@RequestMapping("/province")
	public Map<String, Object> getAllPros() {
		List<District> list=districtService.getAllPros();
		return JSONUtil.getJSON(ErrorType.SUCCESS,list);
	}
	
	/**
	 * 根据省份获取城市列表
	 * @param proId 省份id
	 * @return
	 */
	@RequestMapping("/city/{pid}")
	public Map<String, Object> getCitysByPro(@PathVariable("pid") String proId) {
		List<District> list=districtService.getCitysByPro(proId);
		return JSONUtil.getJSON(ErrorType.SUCCESS,list);
	}
	
	/**
	 * 根据城市获取县区列表
	 * @param cityId 城市id
	 * @return
	 */
	@RequestMapping("/county/{cid}")
	public Map<String, Object> getCountysByCity(@PathVariable("cid") String cityId) {
		List<District> list=districtService.getCountysByCity(cityId);
		return JSONUtil.getJSON(ErrorType.SUCCESS,list);
	}
}
